<template>
  <div>
    <el-form :model="formData" label-position="right" label-width="80px">
      <el-form-item label="time字段:">
        <el-date-picker
          type="date"
          placeholder="选择日期"
          v-model="formData.time"
          clearable
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="number1字段:">
        <el-input
          v-model="formData.number1"
          clearable
          placeholder="请输入"
        ></el-input>
      </el-form-item>

      <el-form-item label="number2字段:">
        <el-input
          v-model="formData.number2"
          clearable
          placeholder="请输入"
        ></el-input>
      </el-form-item>

      <el-form-item label="number3字段:">
        <el-input
          v-model="formData.number3"
          clearable
          placeholder="请输入"
        ></el-input>
      </el-form-item>

      <el-form-item label="number4字段:">
        <el-input
          v-model="formData.number4"
          clearable
          placeholder="请输入"
        ></el-input>
      </el-form-item>

      <el-form-item label="number5字段:">
        <el-input
          v-model="formData.number5"
          clearable
          placeholder="请输入"
        ></el-input>
      </el-form-item>

      <el-form-item label="projectId字段:">
        <el-select v-model="formData.projectId" placeholder="请选择" clearable>
          <el-option
            v-for="(item, key) in sys_project_idOptions"
            :key="key"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="save" type="primary">保存</el-button>
        <el-button @click="back" type="primary">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  createSysCaipiaoNumbers,
  updateSysCaipiaoNumbers,
  findSysCaipiaoNumbers,
} from "@/api/sysCaipiaoNumbers"; //  此处请自行替换地址
import infoList from "@/mixins/infoList";
export default {
  name: "SysCaipiaoNumbers",
  mixins: [infoList],
  data() {
    return {
      type: "",
      sys_project_idOptions: [],
      formData: {
        time: new Date(),
        number1: "",
        number2: "",
        number3: "",
        number4: "",
        number5: "",
        projectId: 0,
      },
    };
  },
  methods: {
    async save() {
      let res;
      switch (this.type) {
        case "create":
          res = await createSysCaipiaoNumbers(this.formData);
          break;
        case "update":
          res = await updateSysCaipiaoNumbers(this.formData);
          break;
        default:
          res = await createSysCaipiaoNumbers(this.formData);
          break;
      }
      if (res.code == 0) {
        this.$message({
          type: "success",
          message: "创建/更改成功",
        });
      }
    },
    back() {
      this.$router.go(-1);
    },
  },
  async created() {
    // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (this.$route.query.id) {
      const res = await findSysCaipiaoNumbers({ ID: this.$route.query.id });
      if (res.code == 0) {
        this.formData = res.data.resysCaipiaoNumbers;
        this.type = "update";
      }
    } else {
      this.type = "create";
    }

    await this.getDict("sys_project_id");
  },
};
</script>

<style>
</style>